package at.technikum.fotoalbum.beans;

import java.sql.Date;

import javax.faces.context.FacesContext;

import at.technikum.fotoalbum.database.DatabaseConnector;
import at.technikum.fotoalbum.utils.Utils;

public class Image {

	private long id;
	private String name;		//required
	private String filename;	//required
	private String filetype;
	private String path;		//required
	private Date date;
	private String nick;
	
	/*
	 * create empty image
	 */
	public Image () {
		this.id = 0;
		this.name ="";
		this.filename = "";
		this.filetype = "";
		this.path = "";
		this.date = null;
		this.setNick("");
	}
	
	public Image (String name, String path, String filename) {
		this.setName(name);
		this.setFilename(filename);
		this.setPath(path);
	}
	
	public Image (String name, String path, String filename, Date date) {
		this.setName(name);
		this.setFilename(filename);
		this.setPath(path);
		this.setDate(date);
	}

	public Image (String filename, String path, String name, String filetype, Date date) {
		this.setFilename(filename);
		this.setPath(path);
		this.setName(name);
		this.setFiletype(filetype);
		this.setDate(date);
	}

	public void setID(long id) {
		this.id = id;
	}

	public long getID() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getFilename() {
		return filename;
	}

	public void setFiletype(String filetype) {
		this.filetype = filetype;
	}

	public String getFiletype() {
		return filetype;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getPath() {
		return path;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Date getDate() {
		return date;
	}

	/**
	 * @param nick the nick to set
	 */
	public void setNick(String nick) {
		this.nick = nick;
	}

	/**
	 * @return the nick
	 */
	public String getNick() {
		return nick;
	}
	
	/**
	 * kjk
	 */
	public String showDetails() {
		DatabaseConnector dc = (DatabaseConnector) Utils.getManagedBean("databaseConnector");
		Image detailedImage = dc.getImageFromImagename(FacesContext.getCurrentInstance().getExternalContext()
				.getRequestParameterMap().get("imageDetailInfo"));
		this.name = detailedImage.getName();
		this.filetype = detailedImage.getFiletype();
		this.path = detailedImage.getPath();

		return "/pages/imageDetail.xhtml";
	}

}